import { ref, onMounted, onUnmounted, computed } from 'vue'
export const useMouse = () => {
  let x = ref(0)
  let y = ref(0)
  let move = (e: MouseEvent) => {
    x.value = e.clientX;
    y.value = e.clientY;
  }
  onMounted(() => {
    // 绑定事件
    document.addEventListener("mousemove", move)
  })
  onUnmounted(() => {
    // 卸载后移除事件
    document.removeEventListener("mousemove", move)
  })
  let xCom = computed(() => {
    return x.value * 2
  })
  let yCom = computed(() => {
    return y.value * 2
  })
  let say = () => {
    alert("x是:" + x.value + "y是:" + y.value)
  }
  return { x, y, xCom, yCom, say }
}